//
//  EnergySavingCardView.m
//  cocoapodText
//
//  Created by apple on 16/9/7.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ShiPei.h"
#import "EnergySavingCardView.h"
#import <Foundation/Foundation.h>

@interface EnergySavingCardView()
@end

@implementation EnergySavingCardView

/**
 *  初始化视图属性
 *
 *  @param frame 视图frame
 *
 *  @return self
 */
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //定制View
        self.backgroundColor = [UIColor clearColor];
        self.userInteractionEnabled = YES; //设置为NO后，不再响应touch方法
        self.multipleTouchEnabled = YES;
        //控制子视图不能超出父视图的范围
        self.clipsToBounds = YES;
        //添加子视图
        [self subView];
    }
    return self;
}

//子视图懒加载
-(void)subView{
    //类型图片
    UIImageView *EnergyCardTypeImage=[[UIImageView alloc]initWithFrame:[ShiPei CGRectMakeScale:10 :21 :33 :33]];
    [EnergyCardTypeImage setUserInteractionEnabled:YES];
    [EnergyCardTypeImage setBackgroundColor:[UIColor clearColor]];
    [self addSubview:EnergyCardTypeImage];
    self.EnergyCardTypeImage=EnergyCardTypeImage;
    //类型描述
    UILabel *EnergyCardTypeLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:55 :17 :95 :20]];
    [EnergyCardTypeLabel setUserInteractionEnabled:YES];
    [EnergyCardTypeLabel setText:@""];
    [EnergyCardTypeLabel setTextColor:FUIColorFromRGB(0x333333)];
    [EnergyCardTypeLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:24]]];
    [self addSubview:EnergyCardTypeLabel];
    self.EnergyCardTypeLabel=EnergyCardTypeLabel;
    //概览信息背景
    UIView *GYCardNumberAndUnitBGView=[[UIView alloc]initWithFrame:[ShiPei CGRectMakeScale:55 :40 :95 :25]];
    [self addSubview:GYCardNumberAndUnitBGView];
    //概览
    UILabel *EnergyCardNumberLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:0 :0 :0 :25]];
    [EnergyCardNumberLabel setTextColor:[UIColor whiteColor]];
    [EnergyCardNumberLabel setText:@""];
    [EnergyCardNumberLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:30]]];
    [GYCardNumberAndUnitBGView addSubview:EnergyCardNumberLabel];
    self.EnergyCardNumberLabel=EnergyCardNumberLabel;
    
    //概览单位
    UILabel *EnergyCardUnitLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:0 :0 :0 :25]];
    [EnergyCardUnitLabel setTextColor:[UIColor whiteColor]];
    [EnergyCardUnitLabel setText:@""];
    [EnergyCardUnitLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:20]]];
    [GYCardNumberAndUnitBGView addSubview:EnergyCardUnitLabel];
    self.EnergyCardUnitLabel=EnergyCardUnitLabel;
}

-(void)setCardTypeImage:(NSString *)CardTypeImage{
    [self.EnergyCardTypeImage setImage:[UIImage imageNamed:CardTypeImage]];
}

-(void)setCardTypeLabel:(NSString *)CardTypeLabel{
    [self.EnergyCardTypeLabel setText:CardTypeLabel];
}
-(void)setCardNumberLabel:(NSString *)CardNumberLabel{
    [self.EnergyCardNumberLabel setText:CardNumberLabel];
    [self.EnergyCardNumberLabel sizeToFit];
    CGFloat CardNumberW=self.EnergyCardNumberLabel.frame.size.width;
    CGFloat CardNumberH=self.EnergyCardNumberLabel.frame.size.height;
    CGFloat CardUnitH=self.EnergyCardUnitLabel.frame.size.height;
    
    CGRect UnitFrame=self.EnergyCardUnitLabel.frame;
    UnitFrame.origin.x=CardNumberW;
    UnitFrame.origin.y=(CardNumberH-CardUnitH)/2;
    [self.EnergyCardUnitLabel setFrame:UnitFrame];
}

-(void)setCardUnitLabel:(NSString *)CardUnitLabel{
    [self.EnergyCardUnitLabel setText:CardUnitLabel];
    [self.EnergyCardUnitLabel sizeToFit];
    CGFloat CardNumberW=self.EnergyCardNumberLabel.frame.size.width;
    CGFloat CardNumberH=self.EnergyCardNumberLabel.frame.size.height;
    CGFloat CardUnitH=self.EnergyCardUnitLabel.frame.size.height;
    
    CGRect UnitFrame=self.EnergyCardUnitLabel.frame;
    UnitFrame.origin.x=CardNumberW;
    UnitFrame.origin.y=(CardNumberH-CardUnitH)/2;
    [self.EnergyCardUnitLabel setFrame:UnitFrame];
}

-(void)setLabelColor:(UIColor *)labelColor{
    [self.EnergyCardNumberLabel setTextColor:labelColor];
    [self.EnergyCardUnitLabel setTextColor:labelColor];
}

//登录
-(void)setData{
    if([_delegate respondsToSelector:@selector(onSetData:)]){
        [_delegate onSetData:self];
    }
}

@end
